import { schoolModel, collegeModel, majorModel, classModel, courseModel, kldModel } from "../api/models";
import identities from "@/common/identities";
import status from "../common/status";
import job_titles from "@/common/job_titles";
import class_status from "@/common/class_status";
import grades from "@/common/grades";
import course_types from '@/common/course_types';
import course_status from '@/common/course_status'
import selects from '@/common/selects';
export default {
  data() {
    return {
      selectedSchool: '',
      selectedCollege: '',
      selectedMajor: '',
      selectedClass: '',
      selectedCourse: '',
      selectedKld: '',
      identities: identities.identities,
      status: status.status,
      user_status: status.user_status,
      job_titles: job_titles.job_titles,
      class_status: class_status.status,
      grades: grades.grades,
      course_types: course_types.types,
      course_status: course_status.status,
      question_types: selects.question_types,
      judge_types: selects.judge_types,
      sexes: [
        {
          value: 'M',
          label: '男'
        },{
          value: 'F',
          label: '女'
        }
      ]
    }
  },
  methods: {
    querySchool(queryString, cb) {
      if(queryString == '') return;
      schoolModel.list({
        keyword: queryString
      }, res => {
        let results = res.data.map((v) => {
          return {
            id: v.school_id,
            value: v.school_name
          }
        })
        cb(results)
      })
    },
    selectSchool(item) {
      if(this.search) this.search.school_id = item.id;
      if(this.data) this.data.school_id = item.id;
      this.selectedSchool = item.value;
    },

    queryCollege(queryString, cb) {
      collegeModel.list({
        keyword: queryString,
        school_id: this.search ? this.search.school_id : (this.data ? this.data.school_id : '')
      }, res => {
        let results = res.data.map((v) => {
          return {
            id: v.college_id,
            value: v.college_name
          }
        })
        cb(results)
      })
    },
    selectCollege(item) {
      if(this.search) {
        this.search.college_id = item.id;
      }
      if(this.data) {
        this.data.college_id = item.id;
      }
      this.selectedCollege = item.value;
    },

    queryMajor(queryString, cb) {
      majorModel.list({
        keyword: queryString,
        school_id: this.search ? this.search.school_id : (this.data ? this.data.school_id : ''),
        college_id: this.search ? this.search.college_id : (this.data ? this.data.college_id : '')
      }, res => {
        let results = res.data.map((v) => {
          return {
            id: v.major_id,
            value: v.major_name
          }
        })
        cb(results)
      })
    },
    selectMajor(item) {
      if(this.search) {
        this.search.major_id = item.id;
      }
      if(this.data) {
        this.data.major_id = item.id;
      }
      this.selectedMajor = item.value;
    },

    queryClass(queryString, cb) {
      classModel.list({
        keyword: queryString,
        school_id: this.search ? this.search.school_id : (this.data ? this.data.school_id : ''),
        college_id: this.search ? this.search.college_id : (this.data ? this.data.college_id : ''),
        major_id: this.search ? this.search.major_id : (this.data ? this.data.major_id : ''),
      }, res => {
        let results = res.data.map((v) => {
          return {
            id: v.class_id,
            value: v.class_name
          }
        })
        cb(results)
      })
    },
    selectClass(item) {
      if(this.search) {
        this.search.class_id = item.id;
      }
      if(this.data) {
        this.data.class_id = item.id;
      }
      this.selectedClass = item.value;
    },

    queryCourse(queryString, cb) {
      courseModel.list({
        keyword: queryString,
      }, res => {
        let results = res.data.map((v) => {
          return {
            id: v.course_id,
            value: v.course_name
          }
        })
        cb(results)
      })
    },

    selectCourse(item) {
      if (this.search) {
        this.search.course_id = item.id;
      }
      if (this.data) {
        this.data.course_id = item.id;
      }
      this.selectedCourse = item.value;
    },

    queryKld(queryString, cb) {
      kldModel.list({
        keyword: queryString,
      }, res => {
        let results = res.data.map((v) => {
          return {
            id: v.knowledge_id,
            value: v.knowledge_name
          }
        })
        cb(results)
      })
    },
    selectKld(item) {
      if(this.search) {
        this.search.knowledge_id = item.id;
      }
      if(this.data) {
        this.data.knowledge_id = item.id;
      }
      this.selectedKld = item.value;
    },

    onIdentityChange() {
      this.getList();
    },

    onStatusChange() {
      this.getList();
    },

    onJob_titleChange() {
      this.getList();
    },

    onClass_statusChange() {
      this.getList();
    },

    onGradeChange() {
      this.getList();
    },

    onCourse_typeChange() {
      this.getList()
    },

    onCourse_statusChange() {
      this.getList()
    },

    onQuestionTypeChange() {
      this.getList()
    },

    identityToLabel(identity) {
      let identityLabel;
      this.identities.forEach(v => {
        if (v.value == identity) identityLabel = v.label;
      });
      return identityLabel;

    },

    statusToLabel(status) {
      let statusLabel;
      this.status.map(v => {
        if (v.value == status) statusLabel = v.label;
      });
      return statusLabel;
    },
    userStatusToLabel(status) {
      let statusLabel;
      this.user_status.map(v => {
        if (v.value == status) statusLabel = v.label;
      });
      return statusLabel;
    },

    classStatusToLabel(status) {
      let statusLabel;
      this.class_status.map(v => {
        if (v.value == status) statusLabel = v.label;
      });
      return statusLabel;
    },
    courseStatusToLabel(s) {
      let label;
      this.course_status.map(v => {
        if (v.value == s) label = v.label;
      });
      return label;
    },
    courseTypeToLabel(type) {
      let label;
      this.course_types.map(v => {
        if (v.value == type) label = v.label;
      });
      return label;
    },
    question_typeToLabel(type) {
      let label;
      this.question_types.map(v => {
        if (v.value == type) label = v.label;
      });
      return label;
    },
    chapterDetailLabel(type) {
      if (['M', 'H'].includes(type)) {
        return '图文'
      }else if (type == 'V') {
        return '视频'
      }else{
        return 'PDF'
      }
    },
    subnetToLabel(value) {
      let label;
      selects.subnets.map(v => {
        if (v.value == value) label = v.label;
      });
      return label;
    },
    security_group_to_label(value) {
      let label;
      selects.security_group.map(v => {
        if (v.value == value) label = v.label;
      });
      return label;
    }
  },
}